package com.power.using.mybomb.myapp;

import android.app.Application;

import com.orhanobut.logger.Logger;
import com.power.using.mybomb.base.UniversalImageLoader;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import cn.bmob.newim.BmobIM;

/**
 * Created by 聪明一只哈 on 2020/3/18.
 * Time: 2020/3/18  9:23
 */
public class MyApplication extends Application {

    private static MyApplication INSTANCE;

    public static MyApplication INSTANCE(){
        return INSTANCE;
    }

    private void setInstance(MyApplication app){
        setBmobMyApplication(app);
    }

    private static void setBmobMyApplication(MyApplication app) {
        MyApplication.INSTANCE=app;
    }


    @Override
    public void onCreate() {
        super.onCreate();

        setInstance(this);

        if(getApplicationInfo().packageName.equals(getMyProccessName())){
            BmobIM.init(this);
            BmobIM.registerDefaultMessageHandler(new DemoMessageHandler(this));
        }

        Logger.init("MyBmob");

        UniversalImageLoader.initImageLoader(this);



    }

    public static String getMyProccessName(){
        try {
            File file = new File("/proc/" + android.os.Process.myPid() + "/" + "cmdline");
            BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
            String processName = mBufferedReader.readLine().trim();
            mBufferedReader.close();
            return processName;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
